
package com.zf.admin.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zf.admin.pojo.Paid;
import com.zf.admin.pojo.QueryVo;
import com.zf.admin.pojo.Topaid;
import com.zf.admin.pojo.Zulist;
import com.zf.admin.service.PaidService;
import com.zf.admin.service.TopaidService;
import com.zf.admin.service.UserlistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;


@Controller
@RequestMapping("/paid")
public class PaidController {
    @Autowired
    private PaidService paidService;
    @Autowired
    private TopaidService topaidService;
    @Autowired
    private UserlistService userlistService;

    //管理员查找所有已缴租金列表
    @RequestMapping("/selectall")
    public String selectall(Model model, QueryVo vo, @RequestParam(required = false, defaultValue = "1") Integer page,
                            @RequestParam(required = false, defaultValue = "2") Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Paid> list = paidService.selectall(vo);
        PageInfo<Paid> p = new PageInfo<Paid>(list);
        Double sum = paidService.selectsum(vo);
        model.addAttribute("paid", list);
        model.addAttribute("sum", sum);
        model.addAttribute("p", p);
        model.addAttribute("mainPage", "paid.jsp");
        model.addAttribute("vo", vo);
        return "admin/main1";
    }

    //管理员删除已缴租金记录
    @RequestMapping("/deletepaid")
    public String deletepaid(Integer id) {
        paidService.deletepaid(id);
        return "redirect:selectall";
    }

    //跳到我要收租页面
    @RequestMapping("/showaddpaid")
    public String showaddpaid(Model model, @RequestParam(required = false, defaultValue = "1") Integer page,
                              @RequestParam(required = false, defaultValue = "2") Integer pageSize) throws Exception {
        PageHelper.startPage(page, pageSize);
        List<Zulist> list = paidService.findzuuserlist();
        PageInfo<Zulist> p = new PageInfo<Zulist>(list);
        model.addAttribute("zulist", list);
        model.addAttribute("p", p);
        model.addAttribute("mainPage", "showaddpaid.jsp");
        return "admin/main1";
    }

    //点击收租后跳转到添加租金信息页面
    @RequestMapping("/addpaid")
    public String addpaid(Integer id, Model model) {
        Zulist zulist = paidService.findzukezulist(id);
        model.addAttribute("zulist", zulist);
        model.addAttribute("mainPage", "addpaid.jsp");
        return "admin/main1";
    }

    //添加租金信息到topaid表
    @RequestMapping("/inserttopaid")
    public String inserttopaid(Topaid topaid, Model model) {
        topaidService.inserttopaid(topaid);
        model.addAttribute("error", "inserttopaid");

        return "redirect:showaddpaid";
    }

    //管理员查看所有未缴租金信息
    @RequestMapping("/topaidlist")
    public String topaidlist(Model model, @RequestParam(required = false, defaultValue = "1") Integer page,
                             @RequestParam(required = false, defaultValue = "2") Integer pageSize) {
        QueryVo vo = new QueryVo();
        PageHelper.startPage(page, pageSize);
        List<Topaid> list = topaidService.findtopaid(vo);
        PageInfo<Topaid> p = new PageInfo<Topaid>(list);
        model.addAttribute("topaid", list);
        model.addAttribute("p", p);
        model.addAttribute("mainPage", "topaid.jsp");
        return "admin/main1";
    }

}
